﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace iChip.Hotspots.Models
{
    public class IndexObjects
    {
        
    }

    public class IndexObject
    {
        public IndexObject()
        {
            Fields = new List<Field>();
            FieldValues = new List<FieldValue>();
            
        }
        public Splash Splash { get; set; }
        public List<Field> Fields { get; set; }
        public string Method_Type { get; set; }
        public int FieldValue_Id { get; set; }
        public string User_Type { get; set; }
        public List<FieldValue> FieldValues { get; set; }        
        public Dictionary<int, List<FieldValue>> DicFieldValue 
        { 
            get
            {
                var _dic = new Dictionary<int, List<FieldValue>>();
                if (this.Fields != null)
                {
                    foreach (var item in this.Fields)
                    {
                        var objTemp = this.FieldValues.Where(m => m.Field_Id == item.Field_Id).ToList();
                        if (objTemp != null && objTemp.Count>0)
                        {
                            _dic.Add(item.Field_Id, objTemp);
                        }
                    }

                    return _dic;
                }
                else
                {
                    return null;
                }
            }
        }

        public Dictionary<int, IEnumerable<SelectListItem>> DicSelectListItem
        {
            get
            {
                var _dic = new Dictionary<int, IEnumerable<SelectListItem>>();
                if (this.Fields != null)
                {                    
                    foreach (var item in this.Fields)
                    {
                        var objTemp = this.FieldValues.Where(m => m.Field_Id == item.Field_Id).ToList();
                        if (objTemp != null && objTemp.Count > 0)
                        {
                            var objListTemp = new List<SelectListItem>();
                            foreach (var tmp in objTemp)
                            {
                                objListTemp.Add(new SelectListItem
                                {
                                    Value = tmp.FieldValue_Id.ToString(),
                                    Text = tmp.FieldValue_Value
                                });
                            }

                            _dic.Add(item.Field_Id, objListTemp);
                        }
                    }

                    return _dic;
                }
                else
                {
                    return null;
                }
            }
        }

    }
}